Skip to content

Conversation

@abbyhu2000
Copy link
Member

@abbyhu2000 abbyhu2000 commented Nov 26, 2025

Description

Add auto scroll when new line is added so we see the line we are typing.

Issues Resolved

Screenshot

before:

Screen.Recording.2025-11-25.at.4.12.38.PM.mov

after:

Screen.Recording.2025-11-25.at.4.14.55.PM.mov

Testing the changes

Changelog

  • fix: Add auto scroll when new line is added

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Summary by CodeRabbit

  • Bug Fixes
    • Editor now automatically scrolls to reveal newly added lines when content exceeds the visible area.

✏️ Tip: You can customize this high-level summary in your review settings.

angle943
angle943 previously approved these changes Nov 26, 2025
ruchidh
ruchidh previously approved these changes Nov 26, 2025
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 60.79%. Comparing base (f129a7e) to head (7238b6f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...r/use_query_panel_editor/use_query_panel_editor.ts 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10977   +/-   ##
=======================================
  Coverage   60.79%   60.79%           
=======================================
  Files        4531     4531           
  Lines      122258   122265    +7     
  Branches    20498    20503    +5     
=======================================
+ Hits        74322    74334   +12     
+ Misses      42693    42689    -4     
+ Partials     5243     5242    -1     
Flag Coverage Δ
Linux_1 26.55% <ø> (-0.01%) ⬇️
Linux_2 38.92% <ø> (ø)
Linux_3 39.51% <ø> (+0.01%) ⬆️
Linux_4 33.73% <66.66%> (-0.01%) ⬇️
Windows_1 26.57% <ø> (-0.01%) ⬇️
Windows_2 38.90% <ø> (ø)
Windows_3 39.51% <ø> (+<0.01%) ⬆️
Windows_4 33.73% <66.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

sejli
sejli previously approved these changes Nov 26, 2025
Signed-off-by: abbyhu2000 <[email protected]>
@abbyhu2000 abbyhu2000 dismissed stale reviews from sejli, ruchidh, and angle943 via 7238b6f November 26, 2025 18:41
@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

Changes add automatic scrolling functionality to the query panel editor. When new content is added and exceeds the visible area, the editor automatically scrolls to reveal the last line. Updates include a changelog entry, test mocks supporting line operations, and implementation of the auto-scroll behavior in the editor's content change handler.

Changes

Cohort / File(s) Summary
Documentation
changelogs/fragments/10977.yml
Added changelog fragment documenting the auto-scroll fix for PR #10977.
Auto-scroll Feature
src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.ts
Implemented automatic scrolling to the bottom of the editor when content size changes by revealing the last line if content height exceeds final height.
Test Support
src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.test.ts
Added mocks for getModel (returning an object with getLineCount) and revealLine on the editor mock to enable testing of line-reveal functionality.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify the content height comparison condition (contentHeight > finalHeight) is correct and handles edge cases
  • Confirm that revealLine with the last line index is the appropriate API call for the desired scroll behavior
  • Ensure test mocks accurately reflect the actual editor API signatures

Poem

🐰 When lines pour in, they pile up high,
No need to scroll and squint your eye!
Auto-scroll reveals the way,
Dancing down, bright as day,
Bottom lines shine through! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately describes the main change—adding auto-scroll functionality when new lines are added in the Explore plugin's query editor.
Description check ✅ Passed The description includes a clear summary, before/after screenshots demonstrating the UI change, a changelog entry with proper fix prefix, and a testing checklist, though testing steps and issues resolved sections are incomplete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad3dcd8 and 1053113.

📒 Files selected for processing (3)
  • changelogs/fragments/10977.yml (1 hunks)
  • src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.test.ts (1 hunks)
  • src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: WhiteSource Security Check
🔇 Additional comments (1)
changelogs/fragments/10977.yml (1)

1-2: LGTM!

The changelog entry is properly formatted and accurately documents the auto-scroll feature.

Comment on lines +147 to +148
getModel: jest.fn(() => ({ getLineCount: jest.fn() })),
revealLine: jest.fn(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add test coverage for the auto-scroll feature.

While the mocks for getModel and revealLine are correctly added, there's no test verifying the new auto-scroll behavior. The existing test at lines 432-457 validates layout and scrollbar visibility but doesn't assert that revealLine is called when content exceeds maxHeight.

Add a test case to verify the auto-scroll behavior:

it('should auto-scroll to the last line when content exceeds max height', () => {
  const mockGetLineCount = jest.fn(() => 10);
  mockEditor.getModel.mockReturnValue({ getLineCount: mockGetLineCount });
  mockEditor.getContentHeight.mockReturnValue(150); // Exceeds maxHeight of 100

  const { result } = renderHook(() => useQueryPanelEditor());

  act(() => {
    result.current.editorDidMount(mockEditor);
  });

  // Trigger content size change
  const contentSizeChangeCallback = mockEditor.onDidContentSizeChange.mock.calls[0][0];
  act(() => {
    contentSizeChangeCallback();
  });

  expect(mockGetLineCount).toHaveBeenCalled();
  expect(mockEditor.revealLine).toHaveBeenCalledWith(10);
});
🤖 Prompt for AI Agents
In
src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.test.ts
around lines 147-148, add a new test that mounts the hook and asserts the
auto-scroll behavior: mock editor.getModel to return an object whose
getLineCount returns 10, set mockEditor.getContentHeight to return a value
greater than maxHeight (e.g. 150), call renderHook to create the hook, invoke
result.current.editorDidMount(mockEditor), retrieve and call the registered
onDidContentSizeChange callback from
mockEditor.onDidContentSizeChange.mock.calls[0][0] inside act, then assert the
getLineCount mock was called and mockEditor.revealLine was called with 10 to
verify auto-scroll to the last line.

Comment on lines +316 to +321

// Automatically scroll to the bottom when new lines are added
if (contentHeight > finalHeight) {
const lastLine = editor.getModel()?.getLineCount() || 0;
editor.revealLine(lastLine);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Auto-scroll may disrupt users reviewing earlier content.

The current implementation auto-scrolls on any content size change when content exceeds maxHeight, without checking the user's current scroll position. If a user scrolls up to review earlier content, any content size change (even unrelated to typing) will force them back to the bottom, disrupting their workflow.

Best practice: Only auto-scroll when the user is already near the bottom of the editor. You can check the current scroll position before calling revealLine.

Consider this approach:

 // Automatically scroll to the bottom when new lines are added
 if (contentHeight > finalHeight) {
+  const scrollTop = editor.getScrollTop();
+  const scrollHeight = editor.getScrollHeight();
+  const layoutInfo = editor.getLayoutInfo();
+  const isNearBottom = scrollTop + layoutInfo.height >= scrollHeight - 50; // 50px threshold
+  
+  if (isNearBottom) {
     const lastLine = editor.getModel()?.getLineCount() || 0;
     editor.revealLine(lastLine);
+  }
 }

This ensures auto-scroll only occurs when the user is already viewing content near the bottom, preserving their position if they've scrolled up intentionally.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Automatically scroll to the bottom when new lines are added
if (contentHeight > finalHeight) {
const lastLine = editor.getModel()?.getLineCount() || 0;
editor.revealLine(lastLine);
}
// Automatically scroll to the bottom when new lines are added
if (contentHeight > finalHeight) {
const scrollTop = editor.getScrollTop();
const scrollHeight = editor.getScrollHeight();
const layoutInfo = editor.getLayoutInfo();
const isNearBottom = scrollTop + layoutInfo.height >= scrollHeight - 50; // 50px threshold
if (isNearBottom) {
const lastLine = editor.getModel()?.getLineCount() || 0;
editor.revealLine(lastLine);
}
}
🤖 Prompt for AI Agents
In
src/plugins/explore/public/components/query_panel/query_panel_editor/use_query_panel_editor/use_query_panel_editor.ts
around lines 316 to 321, the current auto-scroll unconditionally reveals the
last line when contentHeight exceeds finalHeight, which forces users back to the
bottom even if they scrolled up; modify the logic to first inspect the editor's
current scroll position (or visible range) and only call
editor.revealLine(lastLine) when the user is already near the bottom (for
example within a small threshold of the bottom in pixels or lines), otherwise do
nothing so their manual scroll position is preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants